package com.meisupic.copyright.notify;

import java.io.Serializable;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component("notifyQueue")
public class NotifyQueue implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Logger LOG = LoggerFactory.getLogger(NotifyQueue.class);

	@Autowired
	private NotifyParam notifyParam;

	/**
	 * 将传过来的对象进行通知次数判断，之后决定是否放在任务队列中
	 * 
	 * @param executeParams
	 * @throws Exception
	 */
	public void addElementToList(Map<String,String> executeParams,int notifyTimes,String callBackUrl) {


		Integer maxNotifyTime = notifyParam.getMaxNotifyTime();

		long time = System.currentTimeMillis();
		Map<Integer, Integer> timeMap = notifyParam.getNotifyParams();
		if (notifyTimes < maxNotifyTime) {
			Integer next = timeMap.get(notifyTimes);
			if (next != null) {
				time += 1000 * 60 * next + 1;
				NotifyTaskPool.tasks.put(new NotifyTask(time, notifyTimes,executeParams,callBackUrl,this));
			}
		}
	}

}
